package com.zonski.jbots.client;

public class FlipFlopIndexFactory implements IndexFactory
{
    private int min;
    private int max;
    private int mod;
    private int div;

    public FlipFlopIndexFactory(int min, int max, int div)
    {
        this.min = min;
        this.max = max;

        this.mod = (max - min)*2;
        this.div = div;
    }

    public int getIndex(int updates)
    {
        int modded = (updates/div) % this.mod;
        int index;
        if(modded < (max - min))
        {
            index = min + modded;
        }else{
            //index = max - (modded - (max - min)); -- same as =>
            index = 2*max - (modded - min);
        }
        return index;
    }
}
